import 'package:flutter/material.dart';
import 'package:local_coffee/components/example/button.dart';
import 'package:local_coffee/components/example/checkbox.dart';
import 'package:local_coffee/components/example/dialog.dart';
import 'package:local_coffee/components/example/index.dart';
import 'package:local_coffee/components/example/pull_to_refresh.dart';
import 'package:local_coffee/components/example/row.dart';
import 'package:local_coffee/components/example/stepper.dart';
import 'package:local_coffee/pages/coupon/index.dart';
import 'package:local_coffee/pages/diningcode/index.dart';
import 'package:local_coffee/pages/login/login_mail.dart';
import 'package:local_coffee/pages/login/login_method.dart';
import 'package:local_coffee/pages/login/user_agreement.dart';
import 'package:local_coffee/pages/order/order_confirm.dart';
import 'package:local_coffee/pages/order/order_detail.dart';
import 'package:local_coffee/pages/order/order_evaluation.dart';
import 'package:local_coffee/pages/order/order_remark.dart';
import 'package:local_coffee/pages/selfstore/index.dart';
import 'package:local_coffee/pages/storedetail/index.dart';
import 'package:local_coffee/pages/toolbar/index.dart';

class Router {
  
  /// 从非 `toolbar` 页面跳转到 `toolbar` 页面的入场动画不一致
  /// 从非 `toolbar` 页面（子页面）跳转到 `toolbar` 页面（主页）实现：
  /// `pushName` 到对应的路由，因为 `Toolbar` 是单例模式，所以只会创建一个
  /// `pushName` 之后，在 `ToolBar`，`initState` 中获取当前的路由，实现切换页面
  static final _routes = {
    N.root: (BuildContext context, {Object args}) => ToolBar(),
    N.mine: (BuildContext context, {Object args}) => ToolBar(),
    N.order: (BuildContext context, {Object args}) => ToolBar(),
    N.shoppingCart: (BuildContext context, {Object args}) => ToolBar(),
    N.menu: (BuildContext context, {Object args}) => ToolBar(arguments: args),
    //
    N.loginMethod: (BuildContext context, {Object args}) => LoginMethod(),
    N.loginMail: (BuildContext context, {Object args}) => LoginMail(),
    N.userAgreement: (BuildContext context, {Object args}) => UserAgreement(),
    N.orderEvaluation: (BuildContext context, {Object args}) => OrderEvaluation(),
    N.orderConfirm: (BuildContext context, {Object args}) => OrderConfirm(),
    N.orderDetail: (BuildContext context, {Object args}) => OrderDetail(args: args),
    N.orderRemark: (BuildContext context, {Object args}) => OrderRemark(),
    N.coupon: (BuildContext context, {Object args}) => Coupon(),
    N.selfStore: (BuildContext context, {Object args}) => SelfStore(),
    N.storeDetail: (BuildContext context, {Object args}) => StoreDetail(),
    N.diningCode: (BuildContext context, {Object args}) => DiningCode(),
    //
    N.exampleWidgetsList: (BuildContext context, {Object args}) => ExampleWidgetsList(args: args),
    N.exampleButton: (BuildContext context, {Object args}) => ExampleCButton(),
    N.exampleStepper: (BuildContext context, {Object args}) => ExampleAStepper(),
    N.exampleDialog: (BuildContext context, {Object args}) => ExampleCDialog(),
    N.exampleRow: (BuildContext context, {Object args}) => ExampleCRow(),
    N.exampleCheckBox: (BuildContext context, {Object args}) => ExampleCCheckBox(),
    N.examplePullToRefresh: (BuildContext context, {Object args}) => ExamplePullToRefresh(),
    // N.exampleStandButton: (BuildContext context, {Object args}) => ExampleStandButton(),
    // N.exampleStandDialog: (BuildContext context, {Object args}) => ExampleStandDialog(),
  };

  static Router _singleton;

  Router._internal();

  factory Router() {
    if (_singleton == null) {
      _singleton = Router._internal();
    }
    return _singleton;
  }
  
  /// 监听 route
  Route getRoutes(RouteSettings settings) {
    String routeName = settings.name;
    final Function builder = Router._routes[routeName];

    if (builder != null) {
      return MaterialPageRoute(
        settings: settings,
        builder: (BuildContext context) => builder(context, args: settings.arguments)
      );
    }

    return null;
  }
}

class N {
  // 菜单
  static const String root = '/';
  static const String menu = '/menu';
  static const String order = '/order';
  static const String shoppingCart = '/shopping_cart';
  static const String mine = '/mine';

  // 组件
  static const String exampleWidgetsList = '/example_index';
  static const String exampleButton = '/example_button';
  static const String exampleStepper = '/example_stepper';
  static const String exampleDialog = '/example_dialog';
  static const String exampleRow = '/example_row';
  static const String exampleCheckBox = '/example_checkbox';
  static const String examplePullToRefresh = '/example_pull_to_refresh';
  static const String exampleStandButton = '/example_stand_button';
  static const String exampleStandDialog = '/example_stand_dialog';

  //
  static const String loginMethod = '/login_method';
  static const String loginMail = '/login_mail';
  static const String userAgreement = '/user_agreement';
  static const String orderConfirm = '/order_confirm';
  static const String orderEvaluation = 'order_evaluation';
  static const String orderDetail = '/order_detail';
  static const String orderRemark = '/order_remark';
  static const String coupon = '/coupon';
  static const String selfStore = '/self_sstore';
  static const String storeDetail = '/store_detail';
  static const String diningCode = '/dining_code';
}

class P {
  static String swiper1 = 'lib/assets/images/home/swiper1.jpg';
  static String swiper2 = 'lib/assets/images/home/swiper2.jpg';
  static String bottomBar = 'lib/assets/images/home/bottom_bar.png';
  static String dialog1 = 'lib/assets/images/menu/dialog1.jpg';
  static String mine1 = 'lib/assets/images/mine/mine1.png';
  static String mine2 = 'lib/assets/images/mine/mine2.jpg';
  static String shoppingCartNull = 'lib/assets/images/shopping_cart_null.png';
  static String order1 = 'lib/assets/images/mine/order1.png';
  static String order2 = 'lib/assets/images/mine/order2.png';
  static String qrCode258 = 'lib/assets/images/QRCode_258.png';
  static String login1 = 'lib/assets/images/logo1.png';
  static String map = 'lib/assets/images/map.png';
}